package com.selebash.ast;

import com.selebash.runtime.ExecutionContext;
import com.selebash.runtime.NestedExecutionProcessor;
import java.util.List;

/**
 * @author sad
 */
public class SequenceAst extends AbstractAst {

    @Override
    public void process(ExecutionContext executionContext) {
        runSequenceElements(executionContext, null);
    }

    public void runSequenceElements(ExecutionContext executionContext, NestedExecutionProcessor processor) {
        runSequenceElements(executionContext, this.getNested(), processor);
    }

    public void runSequenceElements(ExecutionContext executionContext, List<AbstractAst> nodes, NestedExecutionProcessor processor) {
        executionContext.setRunNested(null);
        if (processor == null) {
            processor = new NestedExecutionProcessor();
        }
        processor.run(executionContext, nodes);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        sb.append("[");
        for (AbstractAst node : getNested()) {
            if (!first) {
                sb.append(",");
            }

            sb.append(node.toString());
            first = false;
        }
        sb.append("]");
        return sb.toString();
    }

}
